<template>
  <div id="userHome">
    <el-container>
      <el-header height="70px">
        <div class="container flexbox">
          <div class="logo">
             <router-link to="/"><img src="./assets/zgs_log.png" width="100%"></router-link>
          </div>
          <div class="nav">
            <el-breadcrumb separator="|">
              <el-breadcrumb-item>欢迎您: {{userName}}</el-breadcrumb-item>   
              <el-breadcrumb-item ><span @click="logout">退出</span></el-breadcrumb-item>
            </el-breadcrumb>
          </div>
        </div>
      </el-header>
      <el-main>
       <div class="main_container">
          <div class="left_menu">
            <!-- <el-menu
              default-active="1" router
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose">
              <router-link to="/userHome/personMessage">
                <el-menu-item index="1">               
                    <i class="el-icon-menu"></i>              
                    <span slot="title">个人信息</span>               
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/joinTest">
                <el-menu-item index="2">
                  <i class="el-icon-edit-outline"></i>
                  <span slot="title">我要报考</span>
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/progress">
                <el-menu-item index="3">               
                    <i class="el-icon-time"></i>
                    <span slot="title">进度查询</span>
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/print1">
                <el-menu-item index="4">
                  <i class="el-icon-printer"></i>
                  <span slot="title">打印/下载报名表</span>
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/print2">
                <el-menu-item index="5">
                  <i class="el-icon-printer"></i>
                  <span slot="title">打印/下载测试单</span>
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/score">
                <el-menu-item index="6">
                  <i class="el-icon-search"></i>
                  <span slot="title">成绩查询</span>
                </el-menu-item>
              </router-link>
              <router-link to="/userHome/count">
                <el-menu-item index="7">
                  <i class="el-icon-setting"></i>
                  <span slot="title">账号管理</span>
                </el-menu-item>
              </router-link>
            </el-menu> -->
            <el-menu
              :default-active="$route.path" router
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose">
              <template v-for="(item,index) in $router.options.routes" v-if="item.name='userHome'">
                  <el-menu-item v-for="(term,idx) in item.children" :index="term.path" v-if="term.show" :class="{ 'is-active': term.isActive}">            
                      <i :class="term.iconCls"></i>              
                      <span slot="title">{{term.name}}</span>               
                  </el-menu-item>
              </template>
            </el-menu>
          </div>
          <div class="main_content">
            <router-view></router-view>
          </div>
        </div>
        <footer>
          @copyright
        </footer>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
     userName:'',
     path:''
    }
  },
  watch:{
   "$route" (to,from){
      // console.log(this.$route.path)
      // console.log(this.$router)
      if(this.$route.path=="/userHome/test2"||this.$route.path=="/userHome/test1"){
        this.$router.options.routes[6].children[1].isActive=true;
      }else{
        this.$router.options.routes[6].children[1].isActive=false;
      }
      if(this.$route.path=="/userHome/progressDetail"){
        this.$router.options.routes[6].children[4].isActive=true;
      }else{
        this.$router.options.routes[6].children[4].isActive=false;
      }
    }
  },
  mounted(){
    this.getInfo();
  },
  methods:{
    getInfo(){
      var that=this;
      this.axios({
        url:this.host+'/3v1t.smserver.cn/index.php/student/Modifysysinfo/getinfo',
        method:'post',
        headers:{
              "Content-type":"application/json"
            }

      }).then((res)=>{
        //console.log(res);
        that.userName=res.data.data.account;
      })
    },
    logout(){
      var that=this;
      this.axios({
            url:this.host+'/3v1t.smserver.cn/index.php/index/login/signout',
            method:'post',
            headers:{
              "Content-type":"application/json"
            }
          }).then((res)=>{
            console.log(res);            
            sessionStorage.clear();
            that.$router.push("/");
          })
    },
    handleOpen(key, keyPath) {
        console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
        console.log(key, keyPath);
    },
    getRouterPath(){
      //if()
      this.path=this.$route.path;
    }
  }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
#userHome{
  height:100%;
  .el-container{
    height:100%;
    background:#f4f4f4;
  }
  .container{
    width:100%;
    margin:0 auto;
  }
  header{
      height:60px;
      background:#393D49;
      display:flex;
      align-items: center;
      border-bottom: 1px solid rgba(255,255,255,0.3);
      .flexbox{
        display:flex;
        align-items: center;
        justify-content: space-between;
      }
  }
    footer{
    height:60px;
    text-align:center;
    line-height:60px;
    color:#fff;
    font-size:14px;
    background:#393D49;
 }
  .logo{
    width:350px;
  }
  .nav a,.nav span{
    color:#fff;
    cursor: pointer;
    text-decoration:none;
  }
  .el-main{
    padding:0;
  }
  .el-menu{
    border-right:0px;
  }
  .main-el{
    background:#fff;
    border:1px solid #ddd;
    margin:5px 3px;
    overflow: initial;
  }
  .right{
    background:#fff;
    border:1px solid #ddd;
    margin:5px 0;
    
  }
  .el-aside{
    background:#fff;
    border:1px solid #ddd;
    margin:5px 0;
  }
  .left{
    background:#fff;
    border:1px solid #ddd;
    margin:5px 3px;
    width:200px;
  }
    //整体布局
    .main_container {
      display: flex;
      min-height: 100%;
    }

    .left_menu {
      flex: 0 0 15%;
      width: 200px;
      background:#fff;
      border:1px solid #ddd;
      margin:5px 3px;
      width:200px;
    }

    .main_content {
      flex: 1 1 auto;
      width: 85%;
      background:#fff;
      border:1px solid #ddd;
      margin:5px 0;
    }

  //导航条
  .el-menu-item.is-active {
    color: #409EFF;
    background: rgba(64, 158, 255, 0.2);
  }
  .el-menu li{
    text-align:left;
  }
  .el-menu-item, .el-submenu__title{
    height: 50px;
    line-height: 50px;
  }
}
</style>
